﻿/*
 * main.cpp
 *
 *  Created on: 2014年11月15日
 *      Author: Timothy
 */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include "ccb_connector.h"
#include "ccb_processor.h"

void init_daemon()
{
	pid_t pid;

	if ((pid = fork()) != 0)
		exit(0);

	setpgid(0, 0);

	signal(SIGINT, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGCHLD, SIG_IGN);

	if ((pid = fork()) != 0)
		exit(0);

	umask(0);
}

void sig_term_handle(int iSig)
{
	conn_stopsvc();
	printf("sig_term_handle: ctrl+c \n");
}

int main(int argc, char **argv)
{
	signal(SIGTERM, sig_term_handle); // kill
	signal(SIGINT, sig_term_handle); // Ctrl+c

	init_daemon();
	conn_request_hander_for_recv(pro_recv_pkg_data);
	conn_startsvc(6400);
	return 0;
}

